#include "CudaEpiModel.h"
// #include "../epimodel.h"
// #include "../epimodelparameters.h"

void cudaSimulate(EpiModel& model){

	model.prerun(); 
	cudaInitialize(model); 
	while(model.nTimer<model.nRunLength*2) {
    		if (model.nLogFileInterval>0 && (int)(model.nTimer/2)%model.nLogFileInterval==0) model.log();
    		if (model.bSeedDaily) model.seedinfected();
		
		time_t start = clock();
		
		cout << "time now is " << model.nTimer << " ---------------------------- " << endl;
		
		model.day();

		cout << "cudaday: " << ((double)clock() - start)/ CLOCKS_PER_SEC << endl;
		
		
		start = clock();
		
		if (model.bTravel) model.travel_end();
		model.nTimer++;
    		
		model.night();
		
		cout << "cudanight: " << ((double)clock() - start)/ CLOCKS_PER_SEC << endl;
		
		start = clock();
		
    	if (model.bTravel) model.travel_start();

		model.response();
		model.nTimer++; 
     
		cout << "cudaresponse: " << ((double)clock() - start)/ CLOCKS_PER_SEC << endl;
	 
		// start = clock();
		
		// cudaStats();
		
		// cout << "cuda stats: " << ((double)clock() - start)/ CLOCKS_PER_SEC << endl;
		
		unsigned int nNumSymptomatic=0;
		unsigned int nNumCumulativeSymptomatic=0;
		for (vector< Community >::iterator it = model.commvec.begin();
			it !=  model.commvec.end();
			it++) {
				for (int j=0; j<TAG; j++) {
					nNumCumulativeSymptomatic += (*it).nEverSymptomatic[j];
					nNumSymptomatic += (*it).nsym[j];
				}
		}
		cout << "nNumCumulativeSymptomatic: " << nNumCumulativeSymptomatic << endl;
		cout << "nNumSymptomatic: " << nNumSymptomatic << endl;
		getchar();
	}

}



int main(int argc, char *argv[]) {
	char *configname=NULL;
	char *option=NULL;
	if (argc==3) configname = argv[1];
  	else {
    		cerr << "Usage: " << argv[0] << " configfilename" << endl;
   	 	exit(-1);
  	}
	// cout << "size of int: " << sizeof(int) << endl;
	// cout << "size of ppl: " << sizeof(Person) << endl;
	// cout << "size of Community: " << sizeof(Community) << endl;
	// exit(1);
	
	
  	EpiModelParameters parms(configname);
  	EpiModel model(parms);
	
	// time_t start = clock();
	// cout << "time taken for configuration is " << ((double)clock()-start)/CLOCKS_PER_SEC << " secs" << endl;
	
	option = argv[2];
	bool cuda_run = atoi(option) == 0;
	cout << "started simulation" << endl;

	// for(int i = 0; i < model.nNumCommunities; i++){
		// cout << (model.commvec[i].nLastPerson - model.commvec[i].nFirstPerson) << " ";
	// }
	// cout << endl;
	// exit(1);
	
	if(cuda_run) cudaSimulate(model);
	else model.run();
	
	cout << "finish ... " << endl;
	
	// cout << compareModel(compare_model) << endl;
	// clean();
  	return 0;
}
